package com.wuhongyu.util;

import javax.servlet.http.HttpServletRequest;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 我的封装用的是真的好呀 ,,,哈哈哈哈哈哈
 * @author Administrator
 *
 */
public class MyUtil {


	//截取url字符串,把pageNum干掉
	public static String getUrl(HttpServletRequest request) {
		String servletPath = request.getServletPath();
		String contextPath = request.getContextPath();
		String queryString = request.getQueryString();
		
		if(MyUtil.notEmpty(queryString) && queryString.indexOf("&number")>0) {
			int indexOf = queryString.indexOf("&number");
			queryString = queryString.substring(0,indexOf);
			return contextPath+servletPath+"?"+queryString;
		}else {
			return contextPath+servletPath+"?1=1";
		}
		
	}

	//判断非空字符串
	public static boolean notEmpty(String string) {
		if(string !=null && !"".equals(string.trim())) {
			return true;
		}else {
			return false;
		}
	}
	
	// MD5加密...这个项目里没用到
		public static String encryptMD5(String str) {
			try {
				MessageDigest md = MessageDigest.getInstance("MD5");
				byte[] byteArray = md.digest(str.getBytes());
				BigInteger bi = new BigInteger(1, byteArray);
				return bi.toString(16);
			} catch (NoSuchAlgorithmException e) {
				throw new RuntimeException();
			}
		}

		// 分页
		public static Integer getCurrentPage(Integer currentPage) {
			if (currentPage == null || currentPage < 0) {
				currentPage = 0;
			}
			return currentPage;
		}
}
